package com.example.personalcenter;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ProfileEditActivity extends AppCompatActivity {
    private static final int REQUEST_CODE_INTEREST = 100;
    private String username;
    private TextView tvUsername;
    private TextView tvInterest;
    private Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_edit);

        // 获取用户名
        username = getIntent().getStringExtra("username");

        tvUsername = findViewById(R.id.tv_username);
        tvInterest = findViewById(R.id.tv_interest);
        btnBack = findViewById(R.id.btn_back);

        // 显示用户名
        tvUsername.setText("用户名：" + username);

        // 返回按钮点击事件
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        // 兴趣文本框点击事件，跳转到兴趣选择页面
        tvInterest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ProfileEditActivity.this, InterestSelectActivity.class);
                startActivityForResult(intent, REQUEST_CODE_INTEREST);
            }
        });
    }

    // 接收从兴趣选择页面返回的数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_INTEREST && resultCode == RESULT_OK) {
            if (data != null) {
                String interest = data.getStringExtra("interest");
                if (interest != null && !interest.isEmpty()) {
                    tvInterest.setText("兴趣：" + interest);
                }
            }
        }
    }
}